<template>
	<view>
		<cu-custom :bgcolor="'#fff'" />
		<view v-if="shopList && shopList.length >0">
			<scroll-view scroll-y="true" :style="'height:'+scorllHeight+ 'px;'">
				<view class="shop-list">
					<view class="list-box pt-3 pb-3 pl-4 pr-4 mb-2" v-for="(item, index) in shopList" :key="index">
						<view class="list pb-2">
							<view class="list-header-info d-flex flex-row">
								<view class="d-flex flex-column flex-1">
									<view class="" style="font-size: 32rpx;">
										分类名称: {{item.cat_name}}
									</view>
								</view>
							</view>
							<view class="list-center-info span-20 d-flex flex-column mt-2">
								<view class="d-flex flex-row  span-20" style="color: #999999;">
									<text class="mr-2 font-md span-20">父级分类名称 : <text class="main-text-color">{{item.parent_name}}</text></text>
									<!-- <text class="flex-1 font-md">数量单位: KG</text> -->
								</view>
								<view class="d-flex flex-row  span-20" style="color: #999999;">
									<text class="mr-2 font-md span-20">商品数量 : {{item.goods_num}}</text>
									<!-- <text class="flex-1 font-md">数量单位: KG</text> -->
								</view>
								<view class="d-flex flex-row font-md" style="color: #999999;">
									<text class="mr-2 span-8 font-md">导航栏:{{item.show_in_nav === 0 ? '否' : '是'}}</text>
									<text class="flex-1 font-md">是否显示: <text
											class="main-text-color">{{item.is_show === 0 ? '否' :'是'}}</text></text>
								</view>
								<view class="d-flex flex-row  span-20" style="color: #999999;">
									<text class="mr-2 font-md span-8">价格分级: {{item.grade}}</text>
									<text class="flex-1 font-md">排序:<text
											class="main-text-color">{{item.sort_order}}</text></text>
								</view>
								
							</view>
						</view>
						<view class="list-btn mt-3 d-flex flex-row a-center j-end">
							<button class="mini-btn m-0 mr-2 input-border-color border bg-none main-text-color"
								type="default" size="mini" @click.stop="toDelete(item.id)">删除</button>
							<!-- <button class="mini-btn m-0 mr-2 input-border-color border bg-none main-text-color"
								type="default" size="mini" @click.stop="tochange">转移</button> -->
							<button class="mini-btn m-0 main-bg-color text-white" type="default" size="mini"
								@click.stop="toDetail(item.id)">编辑</button>
						</view>
					</view>

				</view>
				<!-- <view class="d-flex a-center j-center text-light-muted font-md py-3">{{loadtext}}</view> -->
			</scroll-view>
			
		</view>
		<view v-else class="text-center mt-5">
			暂无数据
		</view>
		<view class="button-box p-2">
			<button class="main-bg-color text-white font-md" @click="toAddShop">新增分类</button>
		</view>
	</view>
</template>

<script>
	import title from "@/components/common/title.vue"
	import divider from "@/components/common/divider.vue"
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			title,
			divider,
			cuCustom
		},
		data() {
			return {
				scorllHeight: 500,
				shopList: [],
				loadtext: "上拉加载更多",
				allChecked: false,
				formData: {
					idCard: "",
					name: ""
				}
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res => {
					this.scorllHeight = res.windowHeight - uni.upx2px(300)
				})
			})
		},
		onShow() {
			this.getShopClassList()
		},
		methods: {
			// 上拉加载更多
			loadMore() {
				if (this.loadtext !== '上拉加载更多') return
				this.loadtext = "加载中..."
				setTimeout(() => {

					// 回复状态
					this.loadtext = "上拉加载更多"
				}, 2000)

			},
			tochange() {
				uni.navigateTo({
					url: "./shopChange"
				})
			},
			toDetail(id) {
				uni.navigateTo({
					url: './addClass?id=' + id
				})
			},
			toAddShop() {
				uni.navigateTo({
					url: './addClass'
				})
			},
			toDelete(id) {
				let _that = this
				uni.showModal({
					title: '确认删除?',
					success: function (res) {
						if (res.confirm) {
							interceptor.get('/supplier_applet_api.php?act=removeCategory',{id}).then((res) => {								
								if(res.status === 1){
									uni.showToast({
										title:"删除成功",
										icon:"success",
										success() {
											_that.getShopClassList()
										}
									})
								}else {
									uni.showToast({
										title:res.msg,
										icon:"none"
									})
								}
							})
						}
					}
				});
				
			},
			getShopClassList() {
				this.shopList = []
				interceptor.get('/supplier_applet_api.php?act=cateList', {
					supplier_id: uni.getStorageSync("supplier_id")
				}).then((res) => {
					if (res.status === 1) {
						const { info } = res
						let catList = JSON.parse(JSON.stringify(info.cat_info))
						catList.map((item) => {
							if(item.children && item.children.length > 0){
								item.children.map((child) =>{
									child.parent_name = item.cat_name
									this.shopList.push(child)
								})
							}else {
								item.parent_name = item.cat_name
								this.shopList.push(item)
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.search-box {
		width: 100%;
		height: 160upx;
		background: #fff;

		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;

		.input {
			width: 100%;
			border-radius: 20px;
			overflow: hidden;
			border: 1px solid #BBBBBB;
			position: relative;

			.icon-sousuo {
				position: absolute;
				left: 35upx;
				top: 10upx;
			}

			.search {
				position: absolute;
				right: 40upx;
				top: 8upx;
			}
		}
	}

	.shop-list {
		background: #EBECED;
		height: auto;
		padding: 32rpx;
		box-sizing: border-box;

		.list-box {
			background: #FFFFFF;
			border-radius: 20rpx;
			height: auto;

			.list {
				height: auto;
				border-bottom: 1px dashed #dcdcdc;
			}

			.list-btn {}
		}

	}

	.button-box {
		position: absolute;
		width: 100%;
		bottom: 0;
		background: #fff;
		height: 100rpx;
		box-sizing: border-box;
		height: 140rpx;
	}
</style>